<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>商品管理</title>
		<link rel="stylesheet" type="text/css" href="./bootstrap-3.3.5/css/bootstrap.css">
		<script type="text/javascript" src="./js/jquery-1.11.3.js"></script>
		<script type="text/javascript" src="./bootstrap-3.3.5/js/bootstrap.js"></script>	
		
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/toastr/toastr.css">		
		<script type="text/javascript" src="${pageContext.request.contextPath}/toastr/toastr.js"></script>		
		
		
		<script type="text/javascript">
			toastr.options = {"timeOut":1000}
			var uid = 0;
			var trobj;
			$(function(){
				/*
					当点击确认删除时
					获取当前uid
					Ajax调用servlet删除记录
					根据删除结果提示用户			
				*/
				$("#ok").click(function(){
					$("#myModal").modal('hide');
					$.ajax({
						url:"${pageContext.request.contextPath}/userdelete",
						type:"post",
						dataType:"json",
						async:true,
						data:"uid="+uid,
						success:function(data){
							if(data==1){
								//隐藏当前行
								trobj.hide();
								toastr.success("删除成功！");
							}else{
								toastr.success("删除失败！");
							}
						}
					})					
				})
			})
			
			function showd(uid_,obj){
				//桥接对象
				uid = uid_;
				trobj = $(obj).parent().parent();
				$('#myModal').modal("show");
			}		
		</script>						
	</head>
	<style>
	body
	{
		background-color:#d0e4fe;
	}
	</style>
	<body style=" padding-top: 100px;">
		<div class="container">
			<jsp:include page="../../header.jsp"></jsp:include>
		
		<h2 class="page-header"><a href="js">商品列表</a></h2>
		 <form class="form-inline" action="userindex" method="post">
			  <div class="form-group">
			    <label for="exampleInputName2">商品名：</label>
			    <input type="text" class="form-control input-sm" id="sname" name="name" value="${user.name }" placeholder="名称">
			  </div><br>
			  <div class="form-group" style="margin-top: 5px;">
			    <label for="exampleInputEmail2">状&nbsp;&nbsp;&nbsp;&nbsp;态：</label>			  
		        <input type="radio" id="all" name="recommend" value="2" ${user.recommend==2?"checked":"" }><label style="font-weight: normal;" for="all">全部</label>&nbsp;
		        <input type="radio" id="yes" name="recommend" value="1" ${user.recommend==1?"checked":"" }><label style="font-weight: normal;" for="yes">上新</label>&nbsp;
		        <input type="radio" id="no" name="recommend" value="0" ${user.recommend==0?"checked":"" }><label style="font-weight: normal;" for="no">下架</label>&nbsp;
			  </div><br>
			  <div class="form-group" style="margin-top: 5px;">
			    <label for="exampleInputEmail2">价&nbsp;&nbsp;&nbsp;&nbsp;格：</label>
			    <input type="text" class="form-control input-sm" id="age" value="${user.age==0?'':user.age}" name="age" placeholder="价格">
			    TO
			    <input type="text" class="form-control input-sm" id="toage" value="${user.toage==0?'':user.age}" name="toage" placeholder="价格">
			  </div>			  
			  <button type="submit" class="btn btn-sm btn-info" style="margin-top: 5px;">查询</button>
		 </form>
		 <hr>
		<table class="table table-striped table-hover">
			<thead>
				<tr>
					<th>商品名</th>
					<th>价格</th>
					<th>尺码</th>
					<th>售后热线</th>									
					<th>生产地址</th>
					<th>评价</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${list}" var="user">
					<tr>
						<td>${user.name }</td>
						<td>${user.age }</td>
						<td>${user.sex }</td>
						<td>${user.phone }</td>
						<td>${user.address}</td>
						<td>${user.recommend==1?"非常好":"一般"}</td>						
						<td>
								<a href="userinfo?uid=${user.uid }&flag=0" class="btn btn-primary btn-xs">查看</a>
								<a href="userinfo?uid=${user.uid }&flag=1" class="btn btn-warning btn-xs">修改</a>
								<button type="button" class="btn btn-danger btn-xs" onclick="showd(${user.uid}),this">删除</button>
						</td>			
					</tr>	
				
				
				</c:forEach>		
				<c:if test="${empty list }">
					<tr><td colspan="5" class="text-center">此查询无数据......</td></tr>
				</c:if>
						
			</tbody>
		</table>
		</div>
		
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title">温馨提示：</h4>
		      </div>
		      <div class="modal-body">
		        <p>是否确认删除？</p>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <button type="button" id="ok" class="btn btn-primary">确认删除</button>
		      </div>
		    </div><!-- /.modal-content -->
		  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
					
		<!-- 尾部 -->
		<hr>
		<%@include file="../../footer.jsp" %>
	</body>
</html>